﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace OnlineCellphoneStore.SitePages
{
    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["ClientID"] == null)
                {
                    AnonymousContext();
                }
                else
                {
                    UserContext();
                }
            }
        }
        private void AnonymousContext()
        {
            HandleAnonymousLables();
        }
        private void UserContext()
        {
            HandleUserLables();
            AddPurchaseNavigator();
        }
        protected void LogOut_Click(object sender, EventArgs e)
        {
            string Url = "../Main.aspx?LogOut=true";
            Response.Redirect(Url, false);
        }
        private void AddPurchaseNavigator()
        {
            HtmlGenericControl li = new HtmlGenericControl("li");
            HtmlGenericControl anchor = new HtmlGenericControl("a");
            HtmlGenericControl span = new HtmlGenericControl("span");
            HtmlGenericControl text = new HtmlGenericControl("span");

            string Url = "../UserPages/PreviousPurchase.aspx";
            anchor.ID = "RecentPurchasesLink";
            anchor.Attributes.Add("href", Url);
            text.InnerText = " My Previous Purchase";
            span.Attributes.Add("class", "glyphicon glyphicon-th-large");

            anchor.Controls.Add(span);
            anchor.Controls.Add(text);
            li.Controls.Add(anchor);
            NavBar.Controls.Add(li);
        }
        private void HandleUserLables()
        {
            ShopingCartLink.Attributes.Add("href", "../UserPages/ShopingCart.aspx");
            anonymousUserOptions.Attributes.CssStyle.Value = "display: none;";
            registerdUserOptions.Attributes.CssStyle.Value = "display: inline;";
            aHelloUser.InnerHtml += Session["UserName"].ToString();
            aLastEntered.InnerHtml += Session["LastVisit"].ToString();
        }
        private void HandleAnonymousLables()
        {
            ShopingCartLink.Attributes.Add("href", "../Account/Login.aspx");
        }
    }
}